package org.semanticflash.rdf.graph.index
{


	import com.bigflexlib.ds.container.zet.IOSet;
	import com.bigflexlib.ds.container.zet.IOWSet;
	import com.bigflexlib.ds.container.zet.impl.owSet;
	
	import org.semanticflash.rdf.triple.RDFTriple;
	import org.semanticflash.rdf.utils.RDFTestBase;
	import org.semanticflash.rdf.utils.RDFTestingUtil;




	/**
	 * 
	 * @private
	 * 
	 */
	public class RDFTripleIndexTest extends RDFTestBase
	{


		

		public function testGeneral( ):void
		{


			var triples:IOWSet = owSet( );
			
			var index:RDFTripleIndex = new RDFTripleIndex( triples );
			
			
			
			var abc:RDFTriple = triple( "abc" );
			var xyz:RDFTriple = triple( "xyz" );


				assertIndex( index, "a**", "" );			

			triples.add( abc );
			triples.add( xyz );


				assertIndex( index, "***", "abc,xyz" );			
				
	
				assertIndex( index, "a**", "abc" );			
				assertIndex( index, "ab*", "abc" );			
				assertIndex( index, "abc", "abc" );			
				assertIndex( index, "*bc", "abc" );			
				assertIndex( index, "**c", "abc" );			
				assertIndex( index, "*b*", "abc" );			
				
				
				assertIndex( index, "*y*", "xyz" );			
				assertIndex( index, "xyz", "xyz" );			

			
			triples.remove( xyz );
			
				assertIndex( index, "***", "abc" );
				assertIndex( index, "*b*", "abc" );
				
				assertIndex( index, "*y*", "" );
			
			
			triples.clear( );
					
			
				assertIndex( index, "***", "" );
				assertIndex( index, "a**", "" );
				assertIndex( index, "x**", "" );
				assertIndex( index, "t**", "" );
					
		
		
		}







		/**
		 * 
		 * @param index
		 * @param mask
		 * @param containedTriples
		 * 
		 */
		private function assertIndex( index:RDFTripleIndex, mask:String, containedTriples:String ):void
		{
			
			var tripleMask:RDFTriple = triple( mask );
			var zet:IOSet = index.getTriples( tripleMask );
			
			assertTrue( RDFTestingUtil.testTripleSetContent( 
				zet, containedTriples 
				) );
		
		
		}








		
	}
	
	
}